package org.despair2D.ui.core 
{
	import flash.events.Event;
	import flash.geom.Point;
	import org.despair2D.core.EventDispatcherAdvance;
	import org.despair2D.debug.Logger;
	import org.despair2D.renderer.IView;
	import org.despair2D.ui.events.InteractiveEvent;
	import org.despair2D.ui.events.ManipulateEvent;
	
	import org.despair2D.core.ns_despair;
	use namespace ns_despair;
	
	
	/** @inheritDoc **/
public class Component extends SpriteAdvance
{
	
	public function Component()
	{
		UIManager.registerComp(this)
	}
	
	
	
	final public function get globalPos() : Point
	{
		m_cachedPoint.x = this.x;
		m_cachedPoint.y = this.y;
		return this.parent.localToGlobal(m_cachedPoint);
	}
	
	
	final public function get layer() : int
	{
		if (this.parent)
		{
			return this.parent.getChildIndex(this)
		}
		
		return -1
	}

	
	
	final public function moveInStage( x:Number, y:Number ) : void
	{
		m_cachedPoint.x = x
		m_cachedPoint.y = y
		
		var local:Point = this.parent.globalToLocal(m_cachedPoint)
		this.x = local.x
		this.y = local.y
	}
	
	
	final override public function addEventListener ( type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false ) : void
	{
		m_eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
	}
	
	
	final override public function removeEventListener ( type:String, listener:Function, useCapture:Boolean = false ) : void
	{
		m_eventDispatcher.removeEventListener(type, listener, useCapture);
	}
	
	
	final override public function dispatchEvent ( event:Event ) : Boolean
	{
		return m_eventDispatcher.dispatchEvent(event);
	}
	
	
	final override public function hasEventListener ( type:String ) : Boolean
	{
		return m_eventDispatcher.hasEventListener(type);
	}
	
	
	final override public function willTrigger ( type:String ) : Boolean
	{
		return m_eventDispatcher.willTrigger(type);
	}
	
	
	final override public function removeAllEventListeners() : void
	{
		m_eventDispatcher.removeAllEventListeners()
	}
	
	
	override ns_despair function recycle() : void
	{
		m_eventDispatcher.dispatchEvent(new ManipulateEvent(ManipulateEvent.KILLED));
		m_eventDispatcher.removeAllEventListeners();
		super.recycle()
	}
	
	
	
	ns_despair static var m_cachedPoint:Point = new Point();
	
	ns_despair var m_eventDispatcher:EventDispatcherAdvance;
	
	ns_despair var m_proxy:IView;
	
	ns_despair var m_cid:uint;

}

}